Ext.namespace("SysMgr");

SysMgr.GroupList = function() {	
	this.winEdit = null;	
	
    this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '查找',
        tooltip: {text: '查找群组'},
        handler: this.queryGroup,
        scope: this
    });
		
	this.store = new Ext.data.JsonStore({
	    url: '../sysmanager/searchGroup.form?timesnap=' + Date.parse(new Date()),
	    root: 'result',
	    totalProperty: 'total',
        remoteSort: true,
	    fields: ['roleId','roleName','userId','ruserIds','ruserNames']
	});
	//this.store.setDefaultSort('GroupId', 'desc');
	this.column = [
		{header: '角色ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'roleId'},
		{header: '群组名称', sortable: true, align: 'center',width: 20,dataIndex: 'roleName'},
		{header: '用户ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'userId'},
		{header: '关联用户ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'ruserIds'},
		{header: '用户名称', sortable: true, align: 'center',dataIndex: 'ruserNames'}
	];
			
	SysMgr.GroupList.superclass.constructor.call(this, {
		title: '群组管理',
        region: 'center',
        cm: new Ext.grid.ColumnModel(this.column),
        sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
        tbar: [this.btnSearch],
        bbar:new Ext.PagingToolbar({
			 pageSize: 15,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        store:this.store,
        viewConfig: { forceFit: true },
        listeners:{
        	rowdblclick : this.onEdit,
			//render:this.queryGroup
			activate: this.queryGroup
		}
    });
};
Ext.extend(SysMgr.GroupList, Ext.grid.GridPanel, {
	queryGroup:function(btn,event){
		var param={
			start : 0,
			limit : 15
		};
		this.store.load({
			params:param
		});
	},
	onEdit:function(grid, rowIndex,e){		
		if (this.winEdit != null) {
			this.winEdit.destroy();
		}
		var data=grid.store.getAt(rowIndex).data;
		this.winEdit = new SysMgr.GroupEdit(this,data.roleId);
		this.winEdit.show();
		this.winEdit.initWin(data);		
	}
});
